package main

import (
	"fmt"
)

func main() {
	s := "tmmzuxt"
	fmt.Println(lengthOfLongestSubstring(s))
}

func lengthOfLongestSubstring(s string) int {
	if len(s) == 0 {
		return 0
	}
	subMap := make(map[byte]int)
	max := 0
	j := 0
	for i := 0; i < len(s); i++ {
		if _, ok := subMap[s[i]]; ok {
			j = intMax(j, subMap[s[i]]+1)
		}
		subMap[s[i]] = i
		max = intMax(max, i-j+1)
	}
	return max
}

func intMax(a, b int) int {
	if a > b {
		return a
	}
	return b
}
